<?php
namespace app\web\controller;

use app\model\Theme; 
use app\model\Points; 

class LtPoints extends Base
{
    public function Lt_points()
    {
/**
 * Created by 底片云
 * Desc:积分
 * User:cbw
 * Date: 2020/11/29
 */

global $_G,$_P;
$params = $_P;
$themeid = isset($params['themeid'])?$params['themeid']:'';//活动id
if($themeid <= 0){
    $themeid = Theme::getDefaultThemenew();
}
$theme = Theme::getThemeById($themeid);
if (!$theme){
    $response = modelShow(40002);
    return_msg($response, '', 'ajax');
}
$config =   Theme::getConfig($themeid);
$system= $_G['system'];
$ac = !empty($params['ac'])?$params['ac']:'display';
$do = 'Lt_points';
$nickname = isset($params['nickname'])?trim($params['nickname']):'';
$start_day = isset($params['createtime']['start'])?$params['createtime']['start']:time();
$end_day = isset($params['createtime']['end'])?$params['createtime']['end']:time();
if ($ac=='display'){
    $list = Points::getPointsOrSearchFlag($themeid);
}
if ($ac=='search'){
    if ($start_day==$end_day){
        $nickname = '%'.$nickname.'%';
        $list = Points::getPointsOrSearchFlag($themeid,$nickname,'','');
    }else{
        $list = Points::getPointsOrSearchFlag($themeid,$nickname,$start_day,$end_day);
    }

}
$total = count($list);
if ($ac=='del'){
    $p_id = $params['p_id'];
    $points_item = Points::getPointsInfoById($p_id);

    $data = [
        'uid'=>$points_item['uid'],
        'op_type'=>'admindel',
        'type'=>2,
        'op_num'=>(-1*$points_item['op_num']),
        'op_notice'=>'管理员扣除',
        'themeid'=>$themeid,
        'today'=>date("Y-m-d",time())
    ];
    $res = Points::insertPointsFlag($data);
    if ($res){
        $response = modelShow(200,'',[]);
    }else{
        $response =  modelShow(30000,'操作失败',[]);
    }
    return_msg($response, '', 'ajax');
}
$return_clicent = get_defined_vars();
return view('/lt_points', $return_clicent);
}
}